//
//  receiveFirCirAllComment.m
//  tcpoctest
//
//  Created by gump on 5/17/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "receiveFirCirAllComment.h"

#import "FirCirNewsDataSource.h"
#import "FirCirLocalResourceDataSource.h"

#import "FirendCirLocalPathdb.h"

#import "FirCirCommentInfo.h"
#import "FirCirLocalInfo.h"

@implementation receiveFirCirAllComment

-(void)processreceive
{
    //返回 74char(1),12char(1),用户名长度char(1),
    //用户名char(x),动态ID字串长度char(1), 动态ID字串char(x),
    //[发言人用户名长度char(1),发言人用户名char(x),
    //对谁说用户名长度char(1)，对谁说用户名char(x),
    //时间字串长度char(1),时间字串char(x),区分值char(1)1文字\2语音,
    //评论ID长度char(1),评论IDchar(x),二进制数据长度int，
    //二进制数据char(x)]*N时间倒序   备注：如果区分值是语音 二进制数据是URL
    
    //返回 74char(1),12char(1),用户名长度char(1),
    //用户名char(x),动态ID字串长度char(1), 动态ID字串char(x)没有
    
    NSString *mail = [logicsb ReadUnencodeString];
    NSString *strnewid = [logicsb ReadUnencodeString];
    
    FriendStatus *fs = [[DataControl shareControl].fcnewsDS getNewsByID:strnewid];
    
    if (logicsb.mrestLength > 0 && fs != nil) {
        [fs.commentArr removeAllObjects];
        fs.commentsCount = 0;
        
        while (logicsb.mrestLength > 0) {
            FirCirCommentInfo *fcci = [[FirCirCommentInfo alloc] init];
            
            fcci.mail = mail;
            fcci.speaker = [logicsb ReadUnencodeString];
            fcci.speakto = [logicsb ReadUnencodeString];
            fcci.strtime = [logicsb ReadUnencodeString];
            fcci.stIndex = [logicsb ReadChar];
            fcci.commentID = [logicsb ReadUnencodeString];
            int l = [logicsb ReadIntWithTT:NTT_BIG2SMALL];
            fcci.content = [logicsb ReadStringWithLength:l];
            
            [fs.commentArr addObject:fcci.commentID];
            
            if (fcci.stIndex == FCG_ONE_SOUND) {
                FirCirLocalInfo *fclinfo = [[FirCirLocalInfo alloc] init];
                fclinfo.resourceID = fcci.commentID;
                fclinfo.url = fcci.content;
                
                [[DataControl shareControl].fcLocalRecDS AddLocalRs:fclinfo];
                [[DataBaseCtrol shareControl].fircirlocaldatabase insertLocalPath:fclinfo];
            }
            
            [[DataControl shareControl] AddComment:fcci];
        }
        
        [fs SortCommentArr];
        fs.commentsCount = fs.commentArr.count;
        
        [[DataControl shareControl].UICommendDS addUICommand:UC_REFRESHCURVIEW];
    }
    
    [self ShowLog];
}

@end
